using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace MineFlagger {


	public class ConfoundsControl : System.Windows.Forms.UserControl {
		
		ResultingConfoundsConfig _rcConfig;
		
		#region AutoGenVars

		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.CheckBox chkRecursiveOnSinglePath;
		private System.Windows.Forms.RadioButton radFast;
		private System.Windows.Forms.RadioButton radFull;
		public Marksam.Controls.NumberBox numRecursionLimit;
		private System.Windows.Forms.CheckBox chkRecusionLimit;
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;


		#endregion

		public ConfoundsControl() {
			InitializeComponent();
			SetDefaults();
		}

		public ResultingConfoundsConfig ResultingConfoundsConfig {
			get { return _rcConfig; }
			set { 

				if (value.SearchType == SearchType.Full) {
					radFull.Checked = true;
				} else if (value.SearchType == SearchType.Skimpy) {
					radFast.Checked = true;
				}
			
				chkRecursiveOnSinglePath.Checked = _rcConfig.UseRecursively;

				if (value.RecursionLimit != -1) {
					chkRecusionLimit.Checked = true;
					numRecursionLimit.Text = value.RecursionLimit.ToString();
				} else {
					chkRecusionLimit.Checked = false;
					numRecursionLimit.Text = "";
				}

				_rcConfig = value;
			}
		}

		public void SetDefaults() {
			_rcConfig = new ResultingConfoundsConfig();

			radFull.Checked = true;
			chkRecursiveOnSinglePath.Checked = true;
			chkRecusionLimit.Checked = false;
			numRecursionLimit.Text = "50";
		
		}

		private void controlChanged(object sender, System.EventArgs e) {
			chkRecusionLimit.Enabled = chkRecursiveOnSinglePath.Checked;
			numRecursionLimit.Enabled = chkRecursiveOnSinglePath.Checked && chkRecusionLimit.Checked;

			setRCConfig();
		}

		private void setRCConfig() {
			// Search type
			if (radFull.Checked) {
				_rcConfig.SearchType = SearchType.Full;
			} else if (radFast.Checked) {
				_rcConfig.SearchType = SearchType.Skimpy;
			}	

			// Use Recursively
			_rcConfig.UseRecursively = chkRecursiveOnSinglePath.Checked;

			// Recursive limit
			if (chkRecusionLimit.Checked && numRecursionLimit.Text != "") {
				_rcConfig.RecursionLimit = int.Parse(numRecursionLimit.Text);
			} else {
				_rcConfig.RecursionLimit = -1;
			}
		}




		#region AutoGenUtil

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.panel1 = new System.Windows.Forms.Panel();
			this.radFast = new System.Windows.Forms.RadioButton();
			this.radFull = new System.Windows.Forms.RadioButton();
			this.label1 = new System.Windows.Forms.Label();
			this.numRecursionLimit = new Marksam.Controls.NumberBox();
			this.chkRecursiveOnSinglePath = new System.Windows.Forms.CheckBox();
			this.chkRecusionLimit = new System.Windows.Forms.CheckBox();
			this.panel1.SuspendLayout();
			this.SuspendLayout();
			// 
			// panel1
			// 
			this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.radFast,
																				 this.radFull});
			this.panel1.Location = new System.Drawing.Point(51, -7);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(151, 29);
			this.panel1.TabIndex = 14;
			// 
			// radFast
			// 
			this.radFast.Location = new System.Drawing.Point(75, 6);
			this.radFast.Name = "radFast";
			this.radFast.Size = new System.Drawing.Size(45, 17);
			this.radFast.TabIndex = 1;
			this.radFast.Text = "Fast";
			this.radFast.CheckedChanged += new System.EventHandler(this.controlChanged);
			// 
			// radFull
			// 
			this.radFull.Location = new System.Drawing.Point(9, 6);
			this.radFull.Name = "radFull";
			this.radFull.Size = new System.Drawing.Size(57, 17);
			this.radFull.TabIndex = 0;
			this.radFull.Text = "Full";
			this.radFull.CheckedChanged += new System.EventHandler(this.controlChanged);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(-1, 1);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(48, 17);
			this.label1.TabIndex = 13;
			this.label1.Text = "Search:";
			// 
			// numRecursionLimit
			// 
			this.numRecursionLimit.Location = new System.Drawing.Point(159, 45);
			this.numRecursionLimit.Name = "numRecursionLimit";
			this.numRecursionLimit.Size = new System.Drawing.Size(40, 20);
			this.numRecursionLimit.TabIndex = 12;
			this.numRecursionLimit.Text = "";
			this.numRecursionLimit.TextChanged += new System.EventHandler(this.controlChanged);
			// 
			// chkRecursiveOnSinglePath
			// 
			this.chkRecursiveOnSinglePath.Location = new System.Drawing.Point(1, 20);
			this.chkRecursiveOnSinglePath.Name = "chkRecursiveOnSinglePath";
			this.chkRecursiveOnSinglePath.Size = new System.Drawing.Size(179, 24);
			this.chkRecursiveOnSinglePath.TabIndex = 11;
			this.chkRecursiveOnSinglePath.Text = "Recursive on single path";
			this.chkRecursiveOnSinglePath.CheckedChanged += new System.EventHandler(this.controlChanged);
			// 
			// chkRecusionLimit
			// 
			this.chkRecusionLimit.Location = new System.Drawing.Point(21, 44);
			this.chkRecusionLimit.Name = "chkRecusionLimit";
			this.chkRecusionLimit.Size = new System.Drawing.Size(106, 24);
			this.chkRecusionLimit.TabIndex = 10;
			this.chkRecusionLimit.Text = "Recursion limit:";
			this.chkRecusionLimit.CheckedChanged += new System.EventHandler(this.controlChanged);
			// 
			// ConfoundsControl
			// 
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.panel1,
																		  this.label1,
																		  this.numRecursionLimit,
																		  this.chkRecursiveOnSinglePath,
																		  this.chkRecusionLimit});
			this.Name = "ConfoundsControl";
			this.Size = new System.Drawing.Size(202, 67);
			this.panel1.ResumeLayout(false);
			this.ResumeLayout(false);

		}

		#endregion
		#endregion
	}
}
